package com.hzqy.service.industry.medical;

import com.alibaba.fastjson.JSONObject;
import com.hzqy.persistence.dao.industry.AlertDataInfoDao;
import com.hzqy.web.vo.AlertDataInfoVo;
import com.hzqy.web.vo.AlertInfoVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class AlertDataInfoService {
    protected final Logger LOG = LoggerFactory.getLogger(getClass());
    @Resource
    private AlertDataInfoDao alertDataInfoDao;
    
    public int addAlertDataInfo(JSONObject request) {
        LOG.debug(request.toJSONString());
//        System.out.println("在这里输出的================");
//        System.out.println(request.toJSONString());
        AlertDataInfoVo alertDataInfoVo=new AlertDataInfoVo();
        alertDataInfoVo.setF_da_equ_id(request.get("telDeviceId")==null?"":request.get("telDeviceId").toString());
        alertDataInfoVo.setF_da_equ_type(request.get("notifyType")==null?"":request.get("notifyType").toString());
        alertDataInfoVo.setF_da_channel(request.get("channel")==null?"":request.get("telDeviceId").toString());
        alertDataInfoVo.setF_da_data_type(request.get("dataType")==null?"":request.get("dataType").toString());
        alertDataInfoVo.setF_da_msg_id(request.get("messageId")==null?"":request.get("messageId").toString());
        alertDataInfoVo.setF_da_type(request.get("type")==null?null:Integer.parseInt(request.get("type").toString()));
        alertDataInfoVo.setF_da_data(request.get("data")==null?"":request.get("data").toString());
        alertDataInfoVo.setF_da_pushTime(request.get("time")==null?"":request.get("time").toString());
        alertDataInfoVo.setF_da_userId(request.get("userId")==null?"":request.get("userId").toString());
        int i = alertDataInfoDao.insertAlertDataInfo(alertDataInfoVo);
        return i;
    }
    
    public List<AlertDataInfoVo> selectAlertDataInfo(AlertDataInfoVo alertDataInfoVo) {
        List<AlertDataInfoVo> alertDataInfoVoList=new ArrayList<>();
        List<AlertDataInfoVo> alertDataInfoVoList1 = alertDataInfoDao.selectAlertDataInfo(alertDataInfoVo);
        alertDataInfoVoList.add(alertDataInfoVoList1.get(0));
        return alertDataInfoVoList;
    }
    
    public List<AlertDataInfoVo> selectAlertDataInfoByPage(AlertDataInfoVo alertDataInfoVo, int pageSize, int pageNum) {
        Map<String,Object> map=new HashMap<>();
        List<AlertDataInfoVo> alertDataInfoVoList =null;
        List<AlertDataInfoVo> alertDataInfoVoList1 = alertDataInfoDao.selectAlertDataInfo(alertDataInfoVo);
        int total=alertDataInfoVoList1.size();
        int pageTotal=0;
        if (total%pageSize==0){pageTotal=total/pageSize;}
        else {pageTotal=total/pageSize+1;}
        if (pageNum>pageTotal){pageNum=pageTotal;}
        
        map.put("pageNum",(pageNum-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("f_da_id",alertDataInfoVo.getF_da_id());
        map.put("f_da_equ_type",alertDataInfoVo.getF_da_equ_type());
        map.put("f_da_equ_id",alertDataInfoVo.getF_da_equ_id());
        map.put("f_da_msg_id",alertDataInfoVo.getF_da_msg_id());
        map.put("f_da_data_type",alertDataInfoVo.getF_da_data_type());
        map.put("f_da_type",alertDataInfoVo.getF_da_type());
        map.put("f_da_data",alertDataInfoVo.getF_da_data());
        map.put("f_da_channel",alertDataInfoVo.getF_da_channel());
        map.put("f_da_userId",alertDataInfoVo.getF_da_userId());
        map.put("f_da_pushTime",alertDataInfoVo.getF_da_pushTime());
        map.put("f_da_createTime",alertDataInfoVo.getF_da_createTime());
        alertDataInfoVoList = alertDataInfoDao.selectAlertDataInfoByPage(map);
        return alertDataInfoVoList;
    }
}
